PHP新手30天實戰金流
, Laravel6
ECPay 的測試環境不支援退款功能,友人建議改用 Paypal。
Paypal 是美國的第三方支付服務商,允許在使用電子郵件來標識身分的用戶之間轉移資金。
測試帳戶會有 5,000元的餘額可以使用,會綁一張 visa 卡。
composer require paypal/rest-api-sdk-php:*
修改: require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
為 require __DIR__ . '/../vendor/autoload.php';
response
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "1.00",
"currency": "USD"
},
"related_resources": []
}
],
"redirect_urls": {
"return_url": "https://example.com/your_redirect_url.html",
"cancel_url": "https://example.com/your_cancel_url.html"
},
"id": "PAYID-LWK4IXA8CN638723P200923K",
"state": "created",
"create_time": "2019-10-03T09:50:20Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LWK4IXA8CN638723P200923K",
"rel": "self",
"method": "GET"
},
{
"href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-4JL568752W151811B",
"rel": "approval_url",
"method": "REDIRECT"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAYID-LWK4IXA8CN638723P200923K/execute",
"rel": "execute",
"method": "POST"
}
]
}
Redirect user to approval_url: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-4JL568752W151811B